|
The Banker's algorithm, sometimes referred to as the avoidance algorithm, is a resource allocation and deadlock avoidance algorithm developed by Edsger Dijkstra that tests for safety by simulating the allocation of predetermined maximum possible amounts of all resources, and then makes an "s-state" check to test for possible deadlock conditions for all other pending activities, before deciding whether allocation should be allowed to continue. The algorithm was developed in the design process for the THE operating system and originally described (in Dutch) in EWD108.〔 (in Dutch; ''An algorithm for the prevention of the deadly embrace'')〕 When a new process enters a system, it must declare the maximum number of instances of each resource type that it may ever claim; clearly, that number may not exceed the total number of resources in the system. Also, when a process gets all its requested resources it must return them in a finite amount of time. == Resources == For the Banker's algorithm to work, it needs to know four things: *How much of each resource each process could possibly request() *How much of each resource each process is currently holding() *How much of each resource the system currently has available() *How much of each resource the system currently is needed() Resources may be allocated to a process only if it satisfies the following conditions: # request ≤ needed, else set error condition as process has crossed maximum claim made by it. # request ≤ available, else process waits until resources are available. Some of the resources that are tracked in real systems are memory, semaphores and interface access. The Banker's Algorithm derives its name from the fact that this algorithm could be used in a banking system to ensure that the bank does not run out of resources, because the bank would never allocate its money in such a way that it can no longer satisfy the needs of all its customers. By using the Banker's algorithm, the bank ensures that when customers request money the bank never leaves a safe state. If the customer's request does not cause the bank to leave a safe state, the cash will be allocated, otherwise the customer must wait until some other customer deposits enough. Basic data structures to be maintained to implement the Banker's Algorithm: Let n be the number of processes in the system and m be the number of resource types. Then we need the following data structures: * Available: A vector of length m indicates the number of available resources of each type. If Available() = k, there are k instances of resource type Rj available. * Max: An ''n''×''m'' matrix defines the maximum demand of each process. If Max() = k, then Pi may request at most k instances of resource type Rj. * Allocation: An ''n''×''m'' matrix defines the number of resources of each type currently allocated to each process. If Allocation() = k, then process Pi is currently allocated k instances of resource type Rj. * Need: An ''n''×''m'' matrix indicates the remaining resource need of each process. If Need() = k, then Pi may need k more instances of resource type Rj to complete the task. Note: Need() = Max() - Allocation(). 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Banker's algorithm」の詳細全文を読む スポンサード リンク
|